import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

//Tabs = 4
//************************************************************
//	COPYRIGHT 2011 Bread Zeppelin - ALL RIGHTS RESERVED
//
//This file is the product of Bread Zeppelin and cannot be 
//reproduced, copied, or used in any shape or form without 
//the express written consent of Bread Zeppelin.
//************************************************************
//
//	$ID: Concurrent_Assg6
//
//	$Date: Feb 13, 2012
//
//	Reason:
//
//*************************************************************

/** $Author: Ben Hare, Zach Huenink, Philipp Wittmaack, Peter Maresca */
/** $Revision: 1 */

//Default Package

/**
 * 
 */
public class File_Writter {
	
	private FileWriter fstream;
	private BufferedWriter out;
	private ArrayList<String> fileText;
	
	File_Writter(String fileName) {
		
		try { fstream = new FileWriter( fileName + ".txt" ); } 
		catch (IOException e) { System.err.println("Error: " + e.getMessage()); }
		
		this.out = null;
		this.fileText = new ArrayList<String>();
	}
	
	public void addLine(String s) {
		fileText.add( s + "\n" );
	}
	
	public void writeFile() {
		
		try{
			
			out = new BufferedWriter(fstream);
			
			// Create file
			while (fileText.size() > 0) {
				out.write( fileText.remove(0) );
			}
			
			//Close the output stream
			out.close();
			
		}catch (Exception e){//Catch exception if any
			
			System.err.println("Error: " + e.getMessage());
			
		}
		
	}

}
